import { createStore, Store, useStore as useVuexStore } from 'vuex'
import { IRootState, IStoreType } from './type'
import banner from './home/banner/banner'
import songList from './home/songList/songList'
import login from './home/login/login'

const store = createStore<IRootState>({
  state: {
    name: '123',
    loading: false
  },
  getters: {},
  mutations: {
    showLoading(state) {
      state.loading = true
    },
    hideLoading(state) {
      state.loading = false
    }
  },
  actions: {},
  modules: {
    banner,
    songList,
    login
  }
})

export function useStore(): Store<IStoreType> {
  return useVuexStore()
}

export function everyStore() {
  //事件派发
  store.dispatch('songList/setStore')
  store.dispatch('banner/setStore')
  store.dispatch('login/setStore')
}
export default store
